package run.newbug.springboot_demo4_mvc.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import run.newbug.springboot_demo4_mvc.mapper.UserMapperInter;
import run.newbug.springboot_demo4_mvc.pojo.User;

import java.util.List;
@Component
public class UserServiceImpl implements UserService{
    @Autowired
    UserMapperInter userMapperInter;

    @Override
    public List<User> gatAll() {
        return userMapperInter.selectList(null);
    }

    @Override
    public List<User> update(User user) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", user.getId());
        userMapperInter.update(user, queryWrapper);
        return userMapperInter.selectList(null);
    }

    @Override
    public List<User> deleteById(Integer id) {
        userMapperInter.deleteById(id);
        return userMapperInter.selectList(null);
    }

    @Override
    public User getById(Integer id) {
        return userMapperInter.selectById(id);
    }

    @Override
    public List<User> getByUs(User user) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>(user);
        return userMapperInter.selectList(queryWrapper);
    }

    @Override
    public List<User> getByNameLike(String x) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("name", x);
        return userMapperInter.selectList(queryWrapper);
    }

    @Override
    public List<User> deleteByName(User user) {
        userMapperInter.delete(new QueryWrapper<>(user));
        return userMapperInter.selectList(null);
    }

    @Override
    public List<User> inser(User user) {
        userMapperInter.insert(user);
        return userMapperInter.selectList(null);
    }
}
